//
//  ViewController.m
//  MvcTest
//
//  Created by SDMac on 15/5/11.
//  Copyright (c) 2015年 SDMac. All rights reserved.
//

#import "FirstViewController.h"

#import "FirstNextViewController.h"

#import "BaseRequest.h"

@interface FirstViewController ()

@end

@implementation FirstViewController

#pragma mark ---- life cycle

- (void)loadView
{
    _firstView = [[FirstView alloc]initWithFrame:CGRectMake(0, 0, ScreenBunds.size.width, ScreenBunds.size.width)];
    
    [_firstView.btn addTarget:self action:@selector(getAction:) forControlEvents:UIControlEventTouchUpInside];
    
    self.view = _firstView;
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    NSLog(@"内存A:%p,内存B:%p",self.view,_firstView);
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    self.title = @"第一";
    
    _firstViewModel = [[FirstViewModel alloc]init];
    [_firstViewModel getFirstViewModel:_firstViewModel];
    
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    RootViewController *root=(RootViewController *)self.tabBarController;
    [root setTabarHiend:NO];
    self.navigationController.navigationBarHidden=NO;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark ---- UITableViewDelegate

#pragma mark ---- CustomDelegate

#pragma mark ---- event response

-(void)getAction:(UIButton *)sender
{
    FirstNextViewController *tfVC = [[FirstNextViewController alloc]init];
    
    [tfVC returnText:^(NSString *name,NSString *age,NSString *sex){
    
        _firstView.lbl.text = [NSString stringWithFormat:@"姓名:%@,年龄:%@,性别:%@",name,age,sex];
    }];
    
    [self.navigationController pushViewController:tfVC animated:YES];
}

/*
-(void)getAction:(UIButton *)sender
{
    _firstView.lbl.text = [NSString stringWithFormat:@"姓名:%@,年龄:%@,性别:%@",_firstViewModel.name,_firstViewModel.age,_firstViewModel.sex];
    
    BaseRequest *sendRequest = [[BaseRequest alloc] init];
    
    [sendRequest searchVideoWithKeyWord:@"火影忍者" success:^(AFHTTPRequestOperation *operation, id responseObject){
    
        NSDictionary *dic = (NSDictionary *)responseObject;
        
        NSArray *ary = [dic objectForKey:@"results"];
        
        for (NSInteger i = 0;i < ary.count;i++)
        {
            NSDictionary *videoDic = [ary objectAtIndex:i];
            
            NSLog(@"Title:%@",[videoDic objectForKey:@"title"]);
        }
    
    } failure:^(AFHTTPRequestOperation *operation, NSError *error){
        
        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"警告"
                                                       message:@"链接错误"
                                                      delegate:nil
                                             cancelButtonTitle:@"确定"
                                             otherButtonTitles:nil];
        [alertView show];
    }];
}
 */

#pragma mark ---- private methods

#pragma mark ---- getters and setters

-(UIButton*)getButtonWithTitle:(NSString*)title tag:(NSInteger)tag
{
    NSInteger screenWidth = [[UIScreen mainScreen]bounds].size.width;
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.tag = tag;
    btn.titleLabel.font = [UIFont systemFontOfSize:17];
    btn.frame = CGRectMake((tag - 1) * (screenWidth / 5.0), 0, screenWidth / 5.0, 49);
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn setTitle:title forState:UIControlStateNormal];
    
    return btn;
    
}


@end
